import TimeManager from "./TimeManager";
import { TimeUpdateType } from "./TimeDisplay";
import TimeObserver from "./TimeObserver";

export default class CDObserver extends TimeObserver  {

    //递增还是递减
    private updateType:TimeUpdateType = TimeUpdateType.SUB;

    constructor(manager:TimeManager,func:Function,updateType:TimeUpdateType = TimeUpdateType.SUB){
        super(manager,func)
        this.updateType = updateType;
    }


    update(dt){
        // cc.log("update  dt ",dt," this.isAdd ",this.isAdd);
        if(this.updateType == TimeUpdateType.ADD){
            this.time += dt;
            if(this.func){
                this.func(this.time);
            }
        }else{
            if(this.time > 0){
                this.time -= dt;
                if(this.time < 0){
                    this.time = 0;
                }
                if(this.func){
                    this.func(this.time);
                }
            }
        }

    }

 

}
